$(document).ready(function () {
	//监测浏览窗口动态变化
	$(window).resize(function () {
		amend_modal_place( $('#edit_parameter_modal'));//修正弹窗位置  始终处于屏幕中央  编辑
		amend_modal_place( $('#edit_complain_status'));//修正弹窗位置  始终处于屏幕中央  投诉类型管理

		modal_select_warn_level_length();//添加人员弹窗  选择预警级别下拉选择框  长度赋值
	});

	//设置当前页面选中样式
	setting_style_the_page();
	function setting_style_the_page() {
		var first_menu_item = $('#sidebar-nav').find('a[href="#accounts-menu-first-04"]');//获取一级菜单可点击的a标签 "投诉管理"
		var img_nav = first_menu_item.find('.define-nav');//获取导航图片
		var img_left = first_menu_item.find('.define-left');//获取转向图片
		var first_ul = $('#accounts-menu-first-04');//获取一级下拉菜单
		var first_ul_li_one = first_ul.children('li').eq(2);//获取  "患者管理"

		var second_menu_item = $('#sidebar-nav').find('a[href="#accounts-menu-second-04-02"]');//获取二级菜单可点击的a标签
		var second_img_left = second_menu_item.parent().find('.define-left');//获取导航图片
		var second_ul = $('#accounts-menu-second-04-02');//获取二级下拉菜单
		var second_ul_li_one = second_ul.children('li').eq(1);//获取  "投诉参数设置"

		first_menu_item.addClass('define-active');//一级菜单添加左边横线
		img_nav.attr('src','/statics/images/sever_hospital_select.png');//切换导航图片
		img_left.addClass('define-rotate-active');//添加动画类
		first_ul.addClass('in');//展拉一级菜单
		first_ul_li_one.addClass('define-active');//li添加左边横线

		second_menu_item.parent().addClass('define-active');
		second_img_left.addClass('define-rotate-active');
		second_ul.addClass('in');//展开二级菜单
		second_ul_li_one.addClass('define-active');//"患者账号管理"  添加选中样式
	}

	//弹层  修正弹窗位置  始终处于屏幕中央
	function amend_modal_place($modal) {
		var window_width = $(window).width();
		var window_height = $(window).height();
		var width = $modal.width();
		var height = $modal.height();

		var left = ( window_width - width ) / 2;
		var top  = ( window_height - height ) / 2;

		$modal.css('left',left);
		$modal.css('top',top);
	}

	//弹层  全选  反选  展示弹层
	click_show_modal_select();
	function click_show_modal_select() {
		$('#admin_edit_parameter').on('click',function () {
			amend_modal_place( $('#edit_parameter_modal'));//修正弹窗位置  始终处于屏幕中央  编辑
			$('#edit_parameter_modal').modal({keyboard: false});
		});
	}

	//弹层  全选  反选  样式切换
	modal_select_all_no_style();
	function modal_select_all_no_style() {
		var modal_select = $('#modal_select');//获取ul
		modal_select.delegate('.define_select_all','click',function () {
			var first_img_src = $(this).find('img');//获取img
			var img_all_item = $(this).parents('li').find('ul').find('img');
			if(first_img_src.attr('src') == '/statics/images/sever_select_all.png'){
				first_img_src.attr('src','/statics/images/sever_unselect.png');
				img_all_item.attr('src','');
			}else {
				first_img_src.attr('src','/statics/images/sever_select_all.png');
				img_all_item.attr('src','/statics/images/sever_select.png');
			}
		});
	}

	//弹层  全选  反选  功能实现  -->  全选
	modal_select_all_no_function();
	function modal_select_all_no_function() {
		var modal_select = $('#modal_select');//获取ul
		modal_select.delegate('li[class="clearfix"]','click',function () {
			var img = $(this).find('img');//当前选项图片
			var img_all = $(this).parent().find('img');//当前所有图片
			var img_select_all = $(this).parents('li').find('.define_select_all').find('img');//全选  反选
			if(img.attr('src') == '/statics/images/sever_select.png'){
				img.attr('src','');
			}else {
				img.attr('src','/statics/images/sever_select.png');
			}
			modal_select_all_no_judge(img_all,img_select_all);//弹层  全选  反选  判断是否全部选中  当前项图片  全选反选
		});
	}

	//弹层  全选  反选  判断是否全部选中  当前项图片  全选反选
	function modal_select_all_no_judge($img,$select_img) {
		var len = $img.length;
		var count = 0;
		$img.each(function (index,item) {
			if($(item).attr('src') == '/statics/images/sever_select.png'){
				count += 1;
			}
		});
		if(count == len){
			$select_img.attr('src','/statics/images/sever_select_all.png')
		}else {
			$select_img.attr('src','/statics/images/sever_unselect.png')
		}
	}

	//弹层  全选  反选  -->  提交
	function  modal_select_post() {
		var modal_select = $('#modal_select');//获取ul
	}

	//弹层  投诉类型管理
	click_show_modal_status();
	function click_show_modal_status() {
		$('#admin_complain_status').on('click',function () {
			amend_modal_place( $('#edit_complain_status'));//修正弹窗位置  始终处于屏幕中央  投诉类型管理
			$('#edit_complain_status').modal({keyboard: false});
		});
	}

	//弹层  投诉类型管理  删除功能
	modal_status_delete_function();
	function modal_status_delete_function() {
		var modal_add = $('#modal_add');//添加按钮
		var html = '<div class="pull-left">医院<img class="complain_delete" src="/statics/images/sever_delete_parameter.png" alt=""></div>';
		modal_add.on('click',function () {
			modal_add.before( html );
		})
	}

	//弹层  投诉类型管理  添加功能
	modal_status_add_function();
	function modal_status_add_function() {
		var edit_complain_status = $('#edit_complain_status');
		edit_complain_status.delegate('.complain_delete','click',function () {
			$(this).parent().remove();
		})
	}

});